<?php
/**
 * Created by b17
 * 2/28/12 9:01 PM
 */

class PDF extends Task
{

    public function __construct()
    {
        parent::__construct(__DIR__ . DIRECTORY_SEPARATOR . 'pdf.pid', 'pdf');
    }

    protected function doTask()
    {
        $this->_log("Start parsing pdf.");
        $manager = new \Managers\PdfFile();
        $unparsed = $manager->getUnparsedList();
        $totalFiles = count($unparsed);
        $this->_log("Found {$totalFiles} file(s).");
        foreach ($unparsed as $pdfFile) {
            try {
                $pdfReader = new \Managers\Reader\PDF($pdfFile);
                $images = $pdfReader->getImages();
                $pdfImageManager = new \Managers\PdfImage();
                $pdfImageManager->add($pdfFile->getId(), $images);
                $pdfFileManager = new \Managers\PdfFile();
                $pdfFileManager->setParsed($pdfFile);
            } catch (Exception $e) {
                $this->_log($e->getMessage() . PHP_EOL . $e->getTraceAsString());
            }
        }
    }
}
